package com.dhcc.core.modules.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhcc.core.framework.base.service.impl.BaseServiceImpl;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.result.node.ZTreeNode;
import com.dhcc.core.modules.system.dao.PanFolderMapper;
import com.dhcc.core.modules.system.entity.PanFolder;
import com.dhcc.core.modules.system.service.IPanFileService;
import com.dhcc.core.modules.system.service.IPanFolderService;

/**
 * 个人文件夹表数据服务层接口
 * 
 * @ClassName: PanFolderServiceImpl
 * @Description: TODO
 * @author mk
 * @date 2018-09-06 15:01:35
 */
@Service
public class PanFolderServiceImpl extends BaseServiceImpl<PanFolderMapper, PanFolder> implements IPanFolderService {

	@Autowired
	private IPanFileService panFileService;
    /**
     * 获取ztree的节点列表
     *
     * @return
     * @date 2017年2月17日 下午8:28:43
     */
    @Override
    public List<ZTreeNode> tree(Long userId) {
        List<ZTreeNode> tree = this.baseMapper.tree(userId);
        ZTreeNode zTreeNode = ZTreeNode.createRoot();
        zTreeNode.setName("默认文件夹");
        zTreeNode.setIsParent(false);
        zTreeNode.setIsOpen(false);
        List<ZTreeNode> trees = new ArrayList<>();
        trees.add(zTreeNode);
        trees.addAll(tree);
        return trees;
    }
	/**
	 * 删除文件夹
	 * @param folderId
	 */
	@Override
	public void deleteFolder(Long folderId) {
	    Boolean hasFileOfFolder = this.panFileService.hasFileOfFolder(folderId);
	    if(hasFileOfFolder){
	        throw new BizException("文件夹下包含文件，请先删除文件！");
	    }
		this.deleteById(folderId);
	}

}